package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.mapper.AdjustAssetsCardMapper;
import com.zygh.policeasset.mapper.AssetsMapper;
import com.zygh.policeasset.pojo.AdjustAssetsCard;
import com.zygh.policeasset.pojo.Assets;
import com.zygh.policeasset.pojo.vo.AdjustAssetsCardVO;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/AdjustAssetsCardService.class */
public class AdjustAssetsCardService {
    @Autowired
    AdjustAssetsCardMapper adjustAssetsCardMapper;
    @Autowired
    AssetsMapper assetsMapper;

    public PageInfo findAll(int pageNum, int pageSize) {
        List<AdjustAssetsCardVO> adjustAssetsCards = this.adjustAssetsCardMapper.findAll();
        for (AdjustAssetsCardVO adjustAssetsCardVO : adjustAssetsCards) {
            if (!(adjustAssetsCardVO.getAssetsIds() == null || adjustAssetsCardVO.getAssetsIds() == "")) {
                String[] strings = adjustAssetsCardVO.getAssetsIds().split(",");
                List<Assets> assets1 = new ArrayList<>();
                for (String s : strings) {
                    assets1.add(this.assetsMapper.findById(Integer.valueOf(Integer.parseInt(s))));
                }
                adjustAssetsCardVO.setAssetsList(assets1);
            }
            if (!(adjustAssetsCardVO.getBreakAssetsIds() == null || adjustAssetsCardVO.getBreakAssetsIds() == "")) {
                String[] strings2 = adjustAssetsCardVO.getBreakAssetsIds().split(",");
                List<Assets> assets12 = new ArrayList<>();
                for (String s2 : strings2) {
                    assets12.add(this.assetsMapper.findById(Integer.valueOf(Integer.parseInt(s2))));
                }
                adjustAssetsCardVO.setBreakAssetsList(assets12);
            }
        }
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(adjustAssetsCards);
    }

    public Integer add(String reason, Integer userId, Integer type, String assetsIds) {
        AdjustAssetsCard adjustAssetsCard = new AdjustAssetsCard();
        adjustAssetsCard.setReason(reason);
        adjustAssetsCard.setUserId(userId);
        adjustAssetsCard.setType(type);
        adjustAssetsCard.setCreateTime(DateUtil.now());
        adjustAssetsCard.setAssetsIds(assetsIds);
        return this.adjustAssetsCardMapper.add(adjustAssetsCard);
    }

    public Integer update(AdjustAssetsCard adjustAssetsCard) {
        return this.adjustAssetsCardMapper.update(adjustAssetsCard);
    }

    public Integer delete(int id) {
        return this.adjustAssetsCardMapper.delete(id);
    }
}